package main

import (
	"fmt"
	"strconv"
)

type Person struct {
	Name   string
	Age    int
	Sex    string
	Height int
}

func (p Person) PrintInfo() {
	fmt.Printf("姓名：%v，年龄：%v，性别：%v，身高：%v \n", p.Name, p.Age, p.Sex, p.Height)
}

func (p *Person) setInfo(val string, typer string) {
	switch typer {
	case "name":
		p.setName(val)
	case "age":
		valInt, _ := strconv.ParseInt(val, 10, 64)
		p.setAge(valInt)
	case "height":
		valInt, _ := strconv.ParseInt(val, 10, 64)
		p.setHeight(valInt)
	}
}

func (p *Person) setName(name string) {
	p.Name = name
}

func (p *Person) setAge(age int64) {
	p.Age = int(age)
}

func (p *Person) setHeight(height int64) {
	p.Height = int(height)
}

func main() {
	p1 := Person{
		Name:   "张三",
		Age:    25,
		Height: 175,
		Sex:    "男",
	}
	p1.PrintInfo() //姓名：张三，年龄：25，性别：男，身高：175

	p1.setInfo("李四", "name")
	p1.setInfo("20", "age")
	p1.setInfo("178", "height")
	p1.PrintInfo() //姓名：李四，年龄：20，性别：男，身高：178
}
